﻿<?php
/*****************************************
Wer Wird Millionr
TIT10NS Webengeneering Projekt

TStatsView - Statistik-View-Klasse

Autoren: Tobias Schneider
Copyright: 2012 DHBW Mannheim
Codierung: UTF8.
*****************************************/

class TStatsView extends TView{

private static function getNotificationtext($notification) {
	
	$res = "<div id='notificationtext' class='".$notification->getNotificationClass()."'>"
			.parent::getText($notification->getNotificationText())."</div> \n <br />";
	return $res;
}

//ok
public function getForm1(){

	$output = "";

	$output.='<div class="stats">';
	$output.='<div id= "form">';

	$output.='<!--	FORMULAR - Beginn		-->';
	$output.='<form action = "stats.php" method="post">';
	
	$output.='<!--	<form action = "stats_form.php" method="post" target = "_self">			-->'."\n";
	$output.='Top:&nbsp;'."\n";
	$output.="\n";
    $output.='<select class="statsnav" name="count" size="1">'."\n";
	$output.='<option value = "10" selected>10</option>'."\n";
	$output.='<option value = "25">25</option>'."\n";
	$output.='<option value = "50">50</option>'."\n";
	$output.='<option value = "100">100</option>'."\n";
    $output.='</select>';
	$output.='&nbsp;<span class="black">|</span>&nbsp;Kategorie:&nbsp;'."\n";
	$output.='<select class="statsnav" name="categories" size="1">'."\n";
	$output.='<option value = "all" selected>Alle</option>'."\n";

	$output.='<!--Kategorien aus DB einfgen-->'."\n";
	echo $output;
}	

//ok
public function getForm1WithData($data){

	$output = "";
	
	$output.='<div class="stats">';
	$output.='<div id= "form">';

	$output.='<!--	FORMULAR - Beginn		-->';
	$output.='<form action = "stats.php" method="post">';

	$output.='<!--	<form action = "stats_form.php" method="post" target = "_self">			-->'."\n";
	$output.='Top:&nbsp;';
	$output.='<select class="statsnav" name="count" size="1">'."\n";
		if ($data[0]==10){
			$output.='<option value = "10" selected>10</option>'."\n";
		}
		else{
			$output.='<option value = "10">10</option>'."\n";
		}
		if ($data[0]==25){
			$output.='<option value = "25" selected>25</option>'."\n";
		}
		else{
			$output.='<option value = "25">25</option>'."\n";
		}

		if ($data[0]==50){
			$output.='<option value = "50" selected>50</option>'."\n";
		}
		else{
			$output.='<option value = "50">50</option>'."\n";
		}
		
		if ($data[0]==100){
			$output.='<option value = "100" selected>100</option>'."\n";
		}
		else{
			$output.='<option value = "100">100</option>'."\n";
		}

    $output.='</select>';
	$output.='&nbsp;<span class="black">|</span>&nbsp;Kategorie:&nbsp;'."\n";
    $output.='<select class="statsnav" name="categories" size="1">'."\n";
	
	if ($data[1]=='all'){
		$output.='<option value = "all" selected>Alle</option>'."\n";
	}
	else{
		$output.='<option value = "all" >Alle</option>'."\n";
	}
	
		


	$output.='<!--Kategorien aus DB einfgen-->'."\n";
	echo $output;
}	

//ok
public function getForm2(){

	$output = "";
    $output.='</select>'."\n";
	
	$output.='&nbsp;<span class="black">|</span>&nbsp;Spiel-Modus:&nbsp;'."\n";

	$output.="\n";
	$output.='<select class="statsnav" name="gameMode" size="1">'."\n";
	$output.='<option value = "*" selected>Alle</option>'."\n";
	$output.='<option value = "0">nur klassisch</option>'."\n";
	$output.='<option value = "1">nur Risiko</option>'."\n";
    $output.='</select>';


	$output.='&nbsp;<span class="black">|</span>&nbsp;Spieler:&nbsp;'."\n";
    $output.='<select class="statsnav" name="player" size="1">'."\n";
	$output.='<option value = "all" selected>Alle</option>'."\n";
	$output.='<!--Spieler aus DB einfgen-->'."\n";

	echo $output;
}	
	
//ok
public function getForm2WithData($data){

	$output = "";
    $output.='</select>'."\n"."\n";
	
	
	$output.='&nbsp;<span class="black">|</span>&nbsp;Spiel-Modus:&nbsp;'."\n";
	$output.="\n";
	$output.='<select class="statsnav" name="gameMode" size="1">'."\n";
	if ($data[4] == '*'){
		$output.='<option value = "*" selected>Alle</option>'."\n";
		$output.='<option value = "0">nur klassisch</option>'."\n";
		$output.='<option value = "1">nur Risiko</option>'."\n";
	}else if($data[4] == '0'){
		$output.='<option value = "*">Alle</option>'."\n";
		$output.='<option value = "0" selected>nur klassisch</option>'."\n";
		$output.='<option value = "1">nur Risiko</option>'."\n";
	}else if($data[4] == '1'){
		$output.='<option value = "*">Alle</option>'."\n";
		$output.='<option value = "0">nur klassisch</option>'."\n";
		$output.='<option value = "1" selected>nur Risiko</option>'."\n";
	}
    $output.='</select>';
	$output.='&nbsp;<span class="black">|</span>&nbsp;Spieler:&nbsp;'."\n";
    $output.='<select class="statsnav" name="player" size="1">'."\n";
	$output.='<option value = "all" selected>Alle</option>'."\n";
		
	$output.='<!--Spieler aus DB einfgen-->'."\n";

	echo $output;
}	
	
//ok	
public function getForm3(){	

	$output="";

    $output.='</select>'."\n"."\n";
	
	//LAST
	$output.='</br></br></span>&nbsp;Beste Spiele&nbsp;'."\n";
	$output.='<input checked type="radio" id="radio-1-1" name="mode" value="games" class="radio"><label for="radio-1-1"></label>'."\n";
	$output.='&nbsp;<span class="black">|</span>&nbsp;Beste Spieler&nbsp;'."\n";
	$output.='<input type="radio" id="radio-1-2" name="mode" value="users" class="radio"><label for="radio-1-2"></label>'."\n";
	
	$output.='</br></br></br><input class="submit" type="submit" value="Liste anzeigen" />'."\n";
	$output.='<!--	FORMULAR - ENDE			-->'."\n"."\n";
	$output.='</form>';
	$output.='</div>';
	echo $output;
}

public function getForm3WithData($data){	

	$output="";

    $output.='</select>'."\n"."\n";
	
	if ($data[2] == 'games'){
		$output.='</br></br></span>&nbsp;Beste Spiele&nbsp;'."\n";
		$output.='<input checked type="radio" id="radio-1-1" name="mode" value="games" class="radio"><label for="radio-1-1"></label>'."\n";
		$output.='&nbsp;<span class="black">|</span>&nbsp;Beste Spieler&nbsp;'."\n";
		$output.='<input type="radio" id="radio-1-2" name="mode" value="users" class="radio"><label for="radio-1-2"></label>'."\n";
	}
	else if($data[2] == 'users'){
     	$output.='</br></br></span>&nbsp;Beste Spiele&nbsp;'."\n";
		$output.='<input type="radio" id="radio-1-1" name="mode" value="games" class="radio"><label for="radio-1-1"></label>'."\n";
		$output.='&nbsp;<span class="black">|</span>&nbsp;Beste Spieler&nbsp;'."\n";
		$output.='<input checked type="radio" id="radio-1-2" name="mode" value="users" class="radio"><label for="radio-1-2"></label>'."\n";
	}
	
	$output.='</br></br></br><input class="submit" type="submit" value="Liste anzeigen" />'."\n";
	$output.='<!--	FORMULAR - ENDE			-->'."\n"."\n";
	$output.='</form>';
	$output.='</div>';
	echo $output;
}


//ok
public function getTable($data,$tableData){

	$quantity = $data[0];

	$tableRow = "";
		if(count($tableData) > 0){
	$tableRow.= '<div id= "highscore">';
	$tableRow.='<div class="Highscore"><table class="resultchange"> <caption align="top">TOP '.$quantity.'</caption> <thead><tr class="resultchange"><th class="resultchange">Rang</th><th class="resultchange">Spieler</th><th class="resultchange"> Kategorie</th><th class="resultchange"> Risiko</th><th class="resultchange">Ergebnis</th></tr></thead>  <tbody>';

	foreach($tableData as $row){
		
		$count = $row["position"];
		if ($row["nickName"]===false){//=== heißt genau gleich. (0 oder ""==false) ist true; (""===false) ist false
			$userName = '<span class="deletedUser">'.parent::getText('deleteduser').'</span>';
		}else{
			$userName = $row["nickName"];
		}
		$result = $row["result"];
		$category = $row["category"];
		if ($row["isRisk"]==1){
			$risk = " x ";
		}else{
			$risk = " - ";
		}	
		
		$tableRow.='<tr><td class="resultchange"> '.$count.' </td><td class="resultchange">'.$userName.'</td><td class="resultchange">'.$category.'</td><td class="resultchange">'.$risk.'</td><td class="resultchange">'.$result.'</td></tr>';
		
	}

	$tableRow.="   </tbody>\n</table>\n";
	$tableRow.="   </div>"."\n";
	$tableRow.="   </div>"."\n";
	}
	else{
	
	$notification = new TAdminNotification("error", "noGamesInCategory");
	$tableRow.= self::getNotificationtext($notification);
		
	}
	echo $tableRow;

}

//ok
public function fillCategories($allCategories){
	$categorie = '<!--	TStatsView . fillCategories		-->';
	$categorie.="\n";
	$categorie.="\n";
	
	foreach($allCategories as $categoryID => $categoryName)
	{	
		$categorie.='<option value="'.$categoryID.'">'.$categoryName.'</option>'."\n";
	}
	echo $categorie;
	}

//ok
public function fillCategoriesWithData($data,$allCategories){
	$categorie = '<!--	TStatsView . fillCategories		-->';
	$categorie.="\n";
	$categorie.="\n";
	
	foreach($allCategories as $categoryID => $categoryName)
	{
		if ($data[1]==$categoryID){
			$categorie.='<option value="'.$categoryID.'" selected>'.$categoryName.'</option>'."\n";
		}
		else{
			$categorie.='<option value="'.$categoryID.'">'.$categoryName.'</option>'."\n";
		} 
	}
	echo $categorie;
}

//ok
public function getPlayers($players){
	$output = '<!--	TStatsView . getPlayers		-->';
	$output.="\n";
	$output.="\n";

	if (count($players) == 0){
	// Dropdown, all --> selected, nicht mehr mglich
		$output.='<!-- wenn niemand eingeloggt, keine Auswahl von Spielern mglich, immer "Alle"-->'."\n";
	}
	else
	{	
		foreach($players as $user_id => $userName){
			$output.='<option value="'.$user_id.'">'.$userName.'</option>'."\n";
			//$output.=';';
		}

	}
											
	echo $output;
}

//ok
public function getPlayersWithData($selectedUserID,$players){
	$output = '<!--	TStatsView . getPlayers		-->';
	$output.="\n";
	$output.="\n";

	if (count($players) == 0){
	// Dropdown, all --> selected, nicht mehr mglich
		$output.='<!-- wenn niemand eingeloggt, keine Auswahl von Spielern mglich, immer "Alle"-->'."\n";
	}
	else
	{	
	if($selectedUserID != '*'){
		foreach($players as $user_id => $userName){
		
			
				if($user_id == $selectedUserID){
						$output.='<option value="'.$user_id.'" selected>'.$userName.'</option>'."\n";
				}else{
					$output.='<option value="'.$user_id.'">'.$userName.'</option>'."\n";
				}
			}
	}else{
		foreach($players as $user_id => $userName){
		$output.='<option value="'.$user_id.'">'.$userName.'</option>'."\n";
		}
	}
		
	}
											
	echo $output;
}

//ok
public function endContent(){
	echo "</div>";
}

}

?>